package b4.view.component.user
{
	import b4.config.AppearanceConfig;
	import b4.config.Config;
	import b4.model.vo.player.Role;
	import b4.util.Resource;
	import b4.view.component.basic.BasicWidget;
	import b4.view.component.basic.MaskProgressBar;
	
	import flash.display.Sprite;
	import flash.filters.*;
	import flash.text.*;

	public class UserPane extends BasicWidget
	{
		//角色头像
		private var appearanceIcon:Sprite;
		//名字
		private var nameText:TextField;
		//生命条
		private var hpBar:MaskProgressBar;
		//体力条
		private var vpBar:MaskProgressBar;
		//等级
		private var levelIcon:LevelIcon;
		
		public function UserPane()
		{
			super();
			//背景
			var UserPaneBgr:Class = Resource.getClassByName("UserPaneBgr");
			addChild(new UserPaneBgr());
			//头像
			appearanceIcon = new Sprite();
			appearanceIcon.x = 10;
			appearanceIcon.y = 10;
			addChild(appearanceIcon);
			//名字
			nameText = new TextField();
        	nameText.autoSize = TextFieldAutoSize.CENTER;
			nameText.defaultTextFormat = new TextFormat("微软雅黑", 14, 0xFFFFFF);
			nameText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			nameText.selectable = false;
			nameText.x = 180;
			nameText.y = 5;
			addChild(nameText);
			//生命条
			var HPBar:Class = Resource.getClassByName("HealthPointBar");
			hpBar = new MaskProgressBar(HPBar);
			hpBar.percentage = 1;
			hpBar.x = 95;
			hpBar.y = 30;
			addChild(hpBar);
			//体力条
			var VPBar:Class = Resource.getClassByName("VitalityPointBar");
			vpBar = new MaskProgressBar(VPBar);
			vpBar.percentage = 0.9;
			vpBar.x = 95;
			vpBar.y = 52;
			addChild(vpBar);
			//等级
			levelIcon = new LevelIcon();
			levelIcon.x = 65;
			levelIcon.y = 40;
			addChild(levelIcon);
		}
		
		//更新角色
		public function refreshInfo(role:Role):void
		{
			nameText.text = role.name;
			hpBar.percentage = role.health / role.healthMax;
			vpBar.percentage = role.vitality / role.vitalityMax;
			levelIcon.levelText.text = role.level.toString();
		}
		
		public function refreshAppearance(appearanceIndex:int):void
		{
			while (appearanceIcon.numChildren > 0)
				appearanceIcon.removeChildAt(0);
			var appearanceConfig:AppearanceConfig = Config.appearanceConfigs[appearanceIndex];
			var AppearanceIcon:Class = Resource.getClassByName("HumanBeingIcon");//appearanceConfig.iconImg);
			appearanceIcon.addChild(new AppearanceIcon());
		}
		
	}
}